//
//  FSSubmitController.m
//  fanshu
//
//  Created by mh on 16/3/29.
//  Copyright © 2016年 FS. All rights reserved.
//

#import "FSSubMitController.h"
#import "FSSubmitHeaderView.h"
#import "MJRefresh.h"
@interface FSSubMitController ()
@property(nonatomic,strong)NSMutableArray *articleArray;
@end

@implementation FSSubMitController

- (NSMutableArray *)articleArray{
    if (_articleArray == nil) {
        _articleArray = [NSMutableArray array];
    }
    return _articleArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //关闭刷新功能
    self.tableView.mj_header = nil;
    self.tableView.mj_footer = nil;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //设置导航条
    [self setNav];
    
    //设置头部视图
    [self setHeaderView];
    
    //添加数据数组
    [self addDataArray];
}
//添加数据数组   放文章标题
- (void)addDataArray{
    [self.articleArray addObjectsFromArray:@[@"哈哈",@"这是一篇文章"]];
}

//设置头部视图
- (void)setHeaderView{
    FSSubmitHeaderView *sumitHeaderView = [FSSubmitHeaderView submitHeaderView];
    self.tableView.tableHeaderView = sumitHeaderView;
    sumitHeaderView.btnOnClick = ^{
    //加载投稿须知   webView
        FSLog(@"加载投稿须知");
    };
}

//设置导航条内容
- (void)setNav{
    self.title = @"投稿";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStyleDone target:self action:@selector(back)];
    //普通状态
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor redColor];
    dict[NSFontAttributeName] = setFont(14.0f);
    [self.navigationItem.leftBarButtonItem setTitleTextAttributes:dict forState:UIControlStateNormal];
}
//dismiss
- (void)back{
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - TableView delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 0) {//写一篇新文章
        FSLog(@"写一篇新文章");
    }else{//查看文章
        FSLog(@"查看文章%@",self.articleArray[indexPath.row - 1]);
    }
}
#pragma mark - TableView dataSourse
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.articleArray.count + 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ID = @"submitCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    if (indexPath.row == 0) {
        cell.imageView.image = [UIImage imageNamed:@"icon_submit_write"];
        cell.textLabel.text = @"写一篇新文章";
        cell.textLabel.textColor = colorOfText(93, 199, 71);
        
        //设置分割线
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 1)];
        view.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.1f];
        [cell addSubview:view];
    }else{
        cell.textLabel.text = self.articleArray[indexPath.row - 1];
    }
    //设置分割线
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20, cell.height - 1, ScreenWidth, 1)];
    view.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.1f];
    [cell addSubview:view];
    return cell;
}


@end
